import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from '@/utils/router'
import pinia from '@/utils/pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { ApiException } from '@/utils/exception/api-exception.ts'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App).use(router).use(pinia).use(ElementPlus)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

window.addEventListener('unhandledrejection', event => {
  const e = event.reason
  if (e instanceof ApiException) {
    console.error(`业务异常, 状态码:${e.code}, 异常信息:${e.message}`)
  } else if (e instanceof Error) {
    console.error(`基本异常, 异常信息:${e.message}`)
  } else {
    console.error('未知异常')
  }
})

app.mount('#app')
